from django.db import models


# 基类
class BaseClase(models.Model):
    create_time = models.DateTimeField("创建时间",auto_now_add=True,blank=True)
    update_time = models.DateTimeField("更新时间",auto_now=True,blank=True)
    is_delete = models.IntegerField(verbose_name='0是未删除1是删除',default=0, blank=True)

    class Meta:
        abstract = True


# 权限表（1）
class PermissionModel(BaseClase):
    permission_name = models.CharField(verbose_name="权限名称", max_length=25)
    path = models.CharField(verbose_name="权限", max_length=50)

    class Meta:
        db_table = "permission_tb"
        verbose_name = "权限表"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.permission_name


# 角色表（2）
class RoleModel(BaseClase):
    # 角色权限 ， 备注
    role_name = models.CharField(verbose_name="角色名称", max_length=25)
    permission = models.ForeignKey(PermissionModel, on_delete=models.CASCADE, verbose_name="角色权限")

    class Meta:
        db_table = "role_tb"
        verbose_name = "角色表"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.role_name


# 学校表（4）
class SchoolModel(BaseClase):
    school_name = models.CharField(max_length=20, verbose_name="学校名称")

    class Meta:
        db_table = "school_tb"
        verbose_name = "学校表"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.school_name


# 班级表（5）
class TheClassModel(BaseClase):
    the_class_name = models.CharField(max_length=50, verbose_name="班级名称")
    school = models.ForeignKey(SchoolModel, on_delete=models.CASCADE, verbose_name="学校")

    class Meta:
        db_table = "the_class_tb"
        verbose_name = "班级表"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.the_class_name


# 用户表（3）
class UserModel(BaseClase):
    user_name = models.CharField(verbose_name="用户名称", max_length=50)
    role = models.ForeignKey(RoleModel, on_delete=models.CASCADE, verbose_name="角色名称", null=True, blank=True)
    user_img = models.CharField(max_length=255, verbose_name="头像地址", null=True, blank=True)
    user_age = models.IntegerField(verbose_name="用户年龄", null=True, blank=True)
    user_gender = models.CharField(verbose_name="性别", max_length=2,null=True, blank=True)
    user_mobile = models.CharField(verbose_name="手机号", max_length=11,null=True, blank=True)
    password = models.CharField(verbose_name="密码", max_length=16, null=True, blank=True)
    account = models.CharField(verbose_name="账号", max_length=20, null=True, blank=True)
    school = models.ForeignKey(SchoolModel, on_delete=models.CASCADE, null=True, blank=True, verbose_name="所属机构")

    class Meta:
        db_table = "user_tb"
        verbose_name = "学校表"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.user_name


# 教师表（6）
class TeacherModel(BaseClase):
    the_class = models.ForeignKey(TheClassModel, on_delete=models.CASCADE, verbose_name="所属班级")
    user = models.ForeignKey(UserModel, on_delete=models.CASCADE, verbose_name="用户名称")

    class Meta:
        db_table = "teacher_tb"
        verbose_name = "教师表"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.user.user_name


# 学生表（7）
class StudentsModelModel(BaseClase):
    the_class = models.ForeignKey(TheClassModel, on_delete=models.CASCADE, verbose_name="所属班级")
    user = models.ForeignKey(UserModel, on_delete=models.CASCADE, verbose_name="用户名称")

    class Meta:
        db_table = "students_tb"
        verbose_name = "学生表"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.user.user_name


# 类别表（8）
class TypeModel(BaseClase):
    type_name = models.CharField(verbose_name="类别表", max_length=20)

    class Meta:
        db_table = "type_tb"
        verbose_name = "类别表"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.type_name


# 标签表（9）
class LabelModel(BaseClase):
    label_name = models.CharField(verbose_name="标签名", max_length=20)

    class Meta:
        db_table = "label_tb"
        verbose_name = "标签表"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.label_name


# 学习内容表（10）
class LearningContentModel(BaseClase):
    learning_content_name = models.CharField(verbose_name="内容名称", max_length=20)
    user = models.ForeignKey(UserModel, on_delete=models.CASCADE, verbose_name="作者", null=True)
    type = models.ForeignKey(TypeModel, on_delete=models.CASCADE,verbose_name="类别名称")
    label = models.ForeignKey(LabelModel, on_delete=models.CASCADE,verbose_name="标签")
    content = models.CharField(verbose_name="内容", max_length=255)
    is_status = models.BooleanField(verbose_name="是否公开", default=1)

    class Meta:
        db_table = "learning_Content_tb"
        verbose_name = "内容名称"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.learning_content_name


# 学习资源表（12）
class LearningResourcesModel(BaseClase):
    learning_Resources_name = models.CharField(verbose_name="资源",max_length=20)
    user = models.ForeignKey(UserModel, on_delete=models.CASCADE, verbose_name="作者")
    price = models.FloatField(verbose_name="价格")
    describe = models.CharField(verbose_name="描述", max_length=200)

    class Meta:
        db_table = "learning_resources_tb"
        verbose_name = "资源"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.learning_Resources_name


# 学习资料学习内容中间表
class ResourcesContentModel(BaseClase):
    content = models.ForeignKey(LearningContentModel,on_delete=models.CASCADE,verbose_name="所有内容")
    resource = models.ForeignKey(LearningResourcesModel, on_delete=models.CASCADE, verbose_name="所有资料")

    class Meta:
        db_table = "resources_countent_tb"
        verbose_name = "资源"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.resource.learning_Resources_name


# 学习任务表（11）
class LearningTaskModel(BaseClase):
    learning_task_name = models.CharField(verbose_name="任务", max_length=20)
    the_class = models.ForeignKey(TheClassModel, on_delete=models.CASCADE, verbose_name="所属班级")

    class Meta:
        db_table = "learning_task_tb"
        verbose_name = "任务名称"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.learning_task_name


# 学习内容学习任务中间表
class ResourcesTaskModel(BaseClase):
    task = models.ForeignKey(LearningTaskModel,on_delete=models.CASCADE,verbose_name="所属任务")
    content = models.ForeignKey(LearningContentModel,on_delete=models.CASCADE,verbose_name="所有内容", null=True)

    class Meta:
        db_table = "resources_task_tb"
        verbose_name = "资源"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.task.learning_task_name


# 收藏（13）
class CollectModel(BaseClase):
    user = models.ForeignKey(UserModel, on_delete=models.CASCADE, verbose_name="收藏人")
    content = models.ForeignKey(LearningContentModel, on_delete=models.CASCADE, verbose_name="收藏内容", null=True)
    is_collect = models.BooleanField(verbose_name="是否收藏", default=1)

    class Meta:
        db_table = "collect_tb"
        verbose_name = "收藏"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.user.user_name


# 点赞（14）
class LikeModel(BaseClase):
    user = models.ForeignKey(UserModel, on_delete=models.CASCADE, verbose_name="点赞人")
    content = models.ForeignKey(LearningContentModel, on_delete=models.CASCADE, verbose_name="点赞内容", null=True)
    is_like = models.BooleanField(verbose_name="是否收藏",default=1)

    class Meta:
        db_table = "like_tb"
        verbose_name = "点赞"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.user.user_name


# 消息（15）
class MessageModelModel(BaseClase):
    user = models.ForeignKey(UserModel, on_delete=models.CASCADE, verbose_name="发送人")
    content = models.CharField(verbose_name="内容", max_length=20)
    receive = models.CharField(max_length=20,verbose_name="接收人", null=True)

    class Meta:
        db_table = "message_tb"
        verbose_name = "消息"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.user.user_name


# 问候语aa
class Greetings(models.Model):
    content = models.CharField('问候语',max_length=70)
    start_time = models.TimeField('开始时间')
    end_time = models.TimeField('结束时间')

    class Meta:
        db_table = 'greetings_tb'

    def __str__(self):
        return self.content


# 弹幕
# 评论
class ObserverModel(BaseClase):
    user = models.ForeignKey(UserModel, on_delete=models.CASCADE, verbose_name="评论人")
    content = models.CharField(verbose_name="内容", max_length=20)
    cont = models.ForeignKey(LearningContentModel, on_delete=models.CASCADE, verbose_name="评论内容", null=True, blank=True)
    obse = models.ForeignKey('self', on_delete=models.CASCADE, verbose_name="所属评论", null=True, blank=True)

    class Meta:
        db_table = "observer_tb"
        verbose_name = "评论"
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.user.user_name
# 登陆记录
# 搜索记录


# 菜单
class Menu(BaseClase):
    name = models.CharField('菜单名称', max_length=32)
    type = models.BooleanField(verbose_name='0是菜单1是目录')
    path = models.CharField('菜单路径', max_length=64, null=True, blank=True)
    order = models.IntegerField(verbose_name='菜单排序', null=True, blank=True)
    img = models.CharField('菜单图标', max_length=256, null=True, blank=True)
    role = models.IntegerField(verbose_name="所属角色", null=True, blank=True)
    menus = models.ForeignKey('self', on_delete=models.CASCADE, verbose_name='所属菜单', null=True, blank=True)

    class Meta:
        db_table = 'tb_menu'
        verbose_name = '菜单'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name









